import { cloneDeep } from 'lodash-es';

import { isArray, isObject } from '@/utils/is/index';

export const handleList = (list) => {
  const newList = cloneDeep(list);

  newList.forEach((item, key) => {
    if (isArray(item)) {
      item;
    } else if (isObject(item)) {
      newList[key] = handleObj(item);
    } else if (item === undefined || item === null) {
      newList[key] = '-';
    }
  });

  return newList;
};

export const handleObj = (obj) => {
  const newObj = cloneDeep(obj);

  for (const i in newObj) {
    const data = newObj[i];

    if (isArray(data)) {
      newObj[i] = handleList(data);
    } else if (isObject(data)) {
      newObj[i] = handleObj(data);
    } else if (data === undefined || data === null) {
      newObj[i] = '-';
    }
  }

  return newObj;
};
